import axios from "axios";
axios.defaults.timeout = 5000; // 在超时前，所有请求都会等待 5 秒
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
    // axios.defaults.headers.post['Content-Type'] = 'application/json'
    // console.log(axios.defaults.headers, "axios.defaults.headers")
    // axios.defaults.baseURL = 'http://106.53.72.119:8082'; // 配置接口地址
axios.defaults.baseURL = 'http://www.tatian66.cn/'; // 配置接口地址

// const HTTP_BASE = "http://172.20.10.8:8080/item/" //哲恒测试地址 提交
// const HTTP_BASE = "http://106.53.72.119:8081/order/getOrders?openid=oVqRK5OaF7TrwXzpxMI4PiwN41Wc&orderstatus=2"
// axios.defaults.withCredentials = false;

import qs from 'qs'
export function httpRequest(method, url, data) {
    console.log(data, `${url}--------请求发送参数--------`)
    return new Promise(function(resolve, reject) {
        if (method.toLowerCase() == 'get') {
            axios.get(url, {
                params: qs.stringify(data)
            }).then(function(res) {
                console.log(res, `${url}--------请求响应结果--------`)
                resolve(res)
            }).catch(function(err) {
                console.log(err, "get-err")
                reject(err)
            })
        } else {
            axios.post(url, qs.stringify(data))
                .then(function(res) {
                    console.log(res, `${url}--------请求响应结果--------`)
                    resolve(res)
                }).catch(function(err) {
                    console.log(err, "get-err")
                    reject(err)
                })
        }
    })
}

//弹出信息
export function alertMessage(th, action, a) {
    let msg = '',
        type = '';
    switch (a) {
        case '1':
            type = 'success';
            msg = action;
            break;
        case '2':
            type = 'warning';
            msg = action;
            break;
        case '3':
            type = 'info';
            msg = action;
            break;
        case '4':
            type = 'error';
            msg = action;
            break;
        default:
            break;
    }
    th.$message({
        offset: '70',
        showClose: true,
        message: msg,
        type: type,
    });
}

// module.exports = {
//     HTTP_BASE: HTTP_BASE
// }